<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>简单源码 simple example</title> 
</head>
<body>

<?php
/**
 * @file testSQL.php 测试MYsql连接和导出update文件
 * @package 
 * @subpackage 
 * @version $id: 0.1 UTF-8 2009-3-3 下午03:14:26 $
 * @author LD King (mifunny.info)
 * @copyright Copyright (c) 2007 - 2009 MiFunny China Inc. (http://mifunny.info)
 * SELECT `aid` , `body` FROM `nw3_articles_body` WHERE `aid` >=1 AND `aid` <=100 ;
 * UPDATE `test3`.`nw3_articles_body` SET `body` = 'BODY──TEXT' WHERE `nw3_articles_body`.`aid` =1 ;
 * UPDATE `nw3_articles` SET  `status` = 0  where `id` >= 6891
 */
require_once 'func_rewrite.php';
require_once 'func_seo.php';

$dbms='mysql';     //数据库类型
$host='localhost'; //数据库主机名
$dbName='test3';    //使用的数据库
$user='root';      //数据库连接用户名
$pass='shadow.kldoo';          //对应的密码
$charset='utf8';
$dsn="$dbms:host=$host;charset=$charset;dbname=$dbName";

try {
    $dbh = new PDO($dsn, $user, $pass, array(PDO::ATTR_PERSISTENT => true)); //初始化一个PDO对象，就是创建了数据库连接对象$dbh
    echo "MySQL PDO 连接成功<br/>";
    $dbh->exec('SET NAMES "utf8"');
	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
/*	@ $fp=fopen('testsql.sql','a');
	if (!$fp) {
		exit("存储文件打开失败！");
	}
	*/
	
    for($i=3; $i<=3; $i++) {
    	$sqlSelect = "SELECT `aid` , `body` FROM `nw3_articles_body`
    				WHERE `aid` = $i ";
		$result = $dbh->query($sqlSelect);
		$row = $result->fetch(PDO::FETCH_BOTH);
		if (empty($row[0])) {
			continue;
		}else { //结果为空
			//var_dump($row[1]);
			$article = rewrite($row[1]);
			$article = strip_a_tag($article);
			$article = add_tail($article);
			$sqlUpdate = "UPDATE `nw3_articles_body` SET `body` = '$article' WHERE `nw3_articles_body`.`aid` =$row[0] ;";
			file_put_contents('testsql.sql', $sqlUpdate."\t\n", FILE_APPEND);
			//echo $sqlUpdate;
			echo "NO.$i 处理完成!<br />";
			
		} //处理结果
    } //循环生成SQL语句

    
 /*   fclose($fp);*/
	$dbh = null;
} catch (PDOException $e) {
    die ("MySQL Connent Error!: " . $e->getMessage() . "<br/>");
}

?>
</body>
</html>